package com.briup.bookstore.web.controller;

import com.briup.bookstore.common.response.Result;
import com.briup.bookstore.domain.vo.BookVO;
import com.briup.bookstore.service.CollectService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/collect")
@RequiredArgsConstructor
public class CollectController {

    private final CollectService collectService;

    @GetMapping("/")
    public Result<List<BookVO>> queryAllCollect() {
        List<BookVO> books = collectService.queryAllCollect();
        return Result.success(books)
                .apply("查询收藏图书成功");
    }

    @PostMapping("/{bookId}")
    public Result<?> addCollect(@PathVariable Integer bookId) {
        collectService.addCollect(bookId);
        return Result.success();
    }

    @DeleteMapping("/")
    public Result<?> cancelCollect(@RequestBody List<Integer> ids) {
        collectService.cancelCollect(ids);
        return Result.success();
    }
}
